const information = document.getElementById('info')
information.innerText = `本应用正在使用 Chrome (v${API.chrome()}), Node.js (v${API.node()}), 和 Electron (v${API.electron()})`
const func = async () => {
    const response = await window.API.ping()
  }
  
  func()

const input = document.getElementById('input')
const btn1 = document.getElementById('btn1')
const btn2 = document.getElementById('btn2')
btn1.onclick = () => {
    console.log(input.value)
    API.saveFile(input.value)
}
btn2.onclick = async () => {
   let data = await API.readFile()
   alert(data)
}
const setButton = document.getElementById('btn3')
const titleInput = document.getElementById('title')
setButton.addEventListener('click', () => {
  const title = titleInput.value
  API.setTitle(title)
})

const openBtn = document.getElementById('openBtn')
const filePathElement = document.getElementById('filePath')

openBtn.addEventListener('click', async () => {
  const filePath = await API.openFile()
  filePathElement.innerText = filePath
})

const counter = document.getElementById('counter')

API.onUpdateCounter((value) => {
  const oldValue = Number(counter.innerText)
  const newValue = oldValue + value
  counter.innerText = newValue.toString()
  API.counterValue(newValue)
})

document.getElementById('toggle-dark-mode').addEventListener('click', async () => {
  const isDarkMode = await API.toggle()
  document.getElementById('theme-source').innerHTML = isDarkMode ? 'Dark' : 'Light'
})

document.getElementById('reset-to-system').addEventListener('click', async () => {
  await API.system()
  document.getElementById('theme-source').innerHTML = 'System'
})